#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QPushButton>
#include <fstream>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    // 从文件中加载汉堡信息
//    ui->comboBox->addItem("巨无霸");
//    ui->comboBox->addItem("鸡肉汉堡");
//    ui->comboBox->addItem("牛肉汉堡");
    std::ifstream ifs;
    ifs.open("C:/Code/qt/ComboBox_Attribute/1.txt",std::ios_base::in);
    std::string line;
    // getline 获取不到数据时返回false
    while(std::getline(ifs,line))
    {
        // 将string 转化为 QString
        ui->comboBox->addItem(QString::fromStdString(line));
//        //QString 转化为string
//        QString str;
//        std::string s = str.QString::toStdString();
    }


    ui->comboBox_2->addItem("薯条");
    ui->comboBox_2->addItem("鸡块");
    ui->comboBox_2->addItem("鸡翅");

    ui->comboBox_3->addItem("可乐");
    ui->comboBox_3->addItem("雪碧");


}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    qDebug() << ui->label->text() << ui->comboBox->currentText();
    qDebug() << ui->label_2->text() << ui->comboBox_2->currentText();
    qDebug() << ui->label_3->text() << ui->comboBox_3->currentText();
}
